package myTeam.timeShop.service.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import myTeam.timeShop.bean.TbComment;
import myTeam.timeShop.bean.TbDemand;
import myTeam.timeShop.bean.TbUser;
import myTeam.timeShop.dao.CommentDao;
import myTeam.timeShop.dao.UserDao;
import myTeam.timeShop.entity.Comment;
import myTeam.timeShop.entity.User;
import myTeam.timeShop.service.CommentService;
@Service("commentService")
public class CommentServiceImpl implements CommentService {
	@Autowired
	CommentDao commentDao;
	@Autowired
	UserDao userDao;
	@Override
	public TbComment load(String id) {
		// TODO 自动生成的方法存根
		return this.commentDao.load(id);
	}

	@Override
	public TbComment get(String id) {
		// TODO 自动生成的方法存根
		return this.commentDao.get(id);
	}

	@Override
	public List<TbComment> findAll() {
		// TODO 自动生成的方法存根
		return this.commentDao.findAll();
	}

	@Override
	public void persist(TbComment entity) {
		// TODO 自动生成的方法存根
		this.commentDao.persist(entity);
	}

	@Override
	public String save(TbComment entity) {
		// TODO 自动生成的方法存根
		return this.commentDao.save(entity).toString();
	}

	@Override
	public void saveOrUpdate(TbComment entity) {
		// TODO 自动生成的方法存根
		this.commentDao.saveOrUpdate(entity);
	}

	@Override
	public void delete(String id) {
		// TODO 自动生成的方法存根
		this.commentDao.delete(id);
	}

	@Override
	public void flush() {
		// TODO 自动生成的方法存根
		this.commentDao.flush();
	}

	/* （非 Javadoc）
	 * @see myTeam.timeShop.service.CommentService#addCommentChildComment(java.lang.String, java.lang.String, java.lang.String)
	 */
	@Override
	
	public void addCommentChildComment(String commentId, String content,
			String filterUserId) {
		TbComment tbComment = this.get(commentId);
		TbDemand tbDemand  =tbComment.getTbDemand();
		TbUser tbUser = userDao.get(filterUserId);
		
		TbComment comment = new TbComment();
		comment.setCommentContent(content);
		comment.setCommentIsSaw(0);
		comment.setCommentTime(new Date());
		comment.setTbComment(tbComment);
		comment.setTbDemand(tbDemand);
		comment.setTbUser(tbUser);
		
		this.save(comment);
		
	}

	/* （非 Javadoc）
	 * @see myTeam.timeShop.service.CommentService#getAllMyNoSeeComment(java.lang.String)
	 */
	@Override
	
	public List<TbComment> getAllMyNoSeeComment(String filterUserId) {
		List<TbComment> tbCommentList = this.commentDao.getAllMyNoSeeComment(filterUserId);
		List<TbComment> commentList = new ArrayList<TbComment>();
		for(TbComment tbComment:tbCommentList){
			Comment comment = new Comment();
			comment.setCommentContent(tbComment.getCommentContent());
			comment.setCommentDemandId(tbComment.getTbDemand().getDemandId());
			comment.setCommentId(tbComment.getCommentId());
			comment.setCommentIsSaw(tbComment.getCommentIsSaw());
			comment.setCommentTime(tbComment.getCommentTime());
			comment.setCommentUserId(tbComment.getTbUser().getUserId());
			
			User user = new User();
			user.setUserAccount(tbComment.getTbUser().getUserAccount());
			user.setUserFacePath(tbComment.getTbUser().getUserFacePath());
			user.setUserId(tbComment.getTbUser().getUserId());
			user.setUserLevel(tbComment.getTbUser().getUserLevel());
			user.setUserName(tbComment.getTbUser().getUserName());
			user.setUserSchool(tbComment.getTbUser().getUserSchool());
			user.setUserSex(tbComment.getTbUser().getUserSex());
			
			comment.setTbUser(user);
			
			
			
			commentList.add(comment);
		}
		return commentList;
	}

}
